package com.itheima.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;

@Controller
public class FileUploadController {
 @RequestMapping(value = "/fileupload")
    public String fileupload(MultipartFile file,MultipartFile file1,MultipartFile file2, HttpServletRequest request) throws IOException {
     System.out.println("file upload is running ..."+file);

     if (!file.isEmpty()){
         String filename = file.getOriginalFilename();
         String realPath = request.getServletContext().getRealPath("/images");
         file.transferTo(new File(realPath,file.getOriginalFilename()));
     }

     if(!file1.isEmpty()){
         String fileName = file1.getOriginalFilename();
         String realPath = request.getServletContext().getRealPath("/images");
         file1.transferTo(new File(realPath,file1.getOriginalFilename()));
     }
     if(!file2.isEmpty()){
         String fileName = file2.getOriginalFilename();
         String realPath = request.getServletContext().getRealPath("/images");
         file2.transferTo(new File(realPath,file2.getOriginalFilename()));
     }
     return "page.jsp";
 }


}
